package com.javaear.beangenerator;

import com.javaear.beangenerator.tools.StringUtils;

/**
 * context holder is a get config params context
 *
 * @author aooer
 */
public abstract class ContextHolder {

    protected Context context = Configure.getInstance().getContext();

    /**
     * get javaBean file head process result
     *
     * @param isParent is parent
     * @param hasList  hasList
     * @return result
     */
    protected String classHeadCodeTemplate(boolean isParent, boolean hasList) {
        boolean enableCodeTemplate = context.getBoolean("config_code_template_enable");
        if (isParent && enableCodeTemplate)
            return context.getString("config_code_template_copyright")
                    .concat(StringUtils.LINE)
                    .concat(importStr())
                    .concat(StringUtils.LINE).concat(hasList ? "import java.util.List;".concat(StringUtils.LINE).concat(StringUtils.LINE) : "")
                    .concat(context.getString("config_code_template_class").concat(StringUtils.LINE));
        return "";
    }

    /**
     * get packageName
     *
     * @return packageName
     */
    protected String packageName() {
        String packageName = context.getString("config_package_name");
        return StringUtils.isEmpty(packageName) ? "" : packageName;
    }

    /**
     * get importStr
     *
     * @return importStr
     */
    protected String importStr() {
        return StringUtils.isEmpty(packageName()) ? "" : "package ".concat(packageName()).concat(";").concat(StringUtils.LINE);
    }

    /**
     * get destDir
     *
     * @return destDir
     */
    protected String destDir() {
        String destDir = context.getString("config_dest_dir");
        return StringUtils.isEmpty(destDir) ? StringUtils.DEFAULT_DEST_DIR : destDir;
    }

    /**
     * get embedStyle
     *
     * @return embedStyle
     */
    protected boolean embedStyle() {
        String embedStyle = context.getString("config_embed_style");
        return StringUtils.isEmpty(embedStyle) ? true : Boolean.valueOf(embedStyle);
    }
}
